<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/common.css" />
		<link rel="stylesheet" href="../../css/order/setpassword.css" />
	</head>

	<body>
		<div id="setpassword">
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left"></a>
				<h1 class="mui-title">设置支付密码</h1>
				<a class="mui-pull-right success">确定</a>
			</header>
			<div class="mui-content">
				<div class="phone">
					<input type="tel" placeholder="请输入您的手机号码" />
				</div>
				<div class="code">
					<input type="tel" placeholder="短信验证码" id="code" />
					<button type="button" class="mui-btn" id="getCode">发送验证码</button>
				</div>
				<div class="password">
					<input type="password" placeholder="请设置您的6位数支付密码" />
				</div>
				<div class="password">
					<input type="password" placeholder="请再次输入您的支付密码" />
				</div>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init({
				swipeBack:true
			})
			var swithCode = false
			var num = 60
			var temp = num
			var passwords = ''
			var swith = false
			$("#getCode").on("tap", function() {
				if(swithCode) {
					return
				}
				if(!common.phone.test($('.phone input').val())) {
					common.toast('请输入正确的手机号码')
					return
				}
				swithCode = true
				common.ajax('/userCore/sendSMSCode', {
					mobile: $('.phone input').val()
				}, function(data) {
					if(data.code == 1) {
						jishi()
					} else {
						swithCode = false
						if(data.resultMsg) {
							common.toast(data.resultMsg)
						} else {
							console.log(data)
						}
					}
				})
			})
			//倒计时
			function jishi() {
				if(temp >= 0) {
					$('#getCode').text(temp + "s")
					setTimeout(jishi, 1000)
				} else {
					temp = num
					swithCode = false
					$('#getCode').text('重新获取')
				}
				temp--
			}

			$(".password input").on('input', function() {
				var c = $(this);
				if(/[^\d]/.test(c.val())) { //替换非数字字符    
					var temp_amount = c.val().replace(/[^\d]/g, '');
					$(this).val(temp_amount);
					common.toast('请输入6位数字密码')
				}
				if($(this).val() > 6) {
					$(this).val($(this).val().slice(0, 6))
				}
			})

			$(".success").on('tap', function() {
				if(swith) {
					return
				}
				if(!common.phone.test($('.phone input').val())) {
					common.toast('请输入正确的手机号码')
					return
				} else if(common.replace($('#code').val()) == '') {
					common.toast('验证码不能为空')
					return
				} else if(common.replace($(".password input").val()) == '') {
					common.toast('密码不能为空')
					return
				}else if(common.replace($(".password input").val()).length<6){
					common.toast('密码不到6为数')
					return
				}
				else if($(".password input").eq(0).val() != $(".password input").eq(1).val()) {
					common.toast('密码不一致')
					return
				}

				swith = true

				common.ajax('/userCenter/updatePaymentpassword', {
					paymentPassword: $(".password input").val(),
					securityCode: $("#code").val(),
					mobile: $(".phone input").val()
				}, function(data) {
					swith = false
					if(data.code == 1) {
						mui.back()
						mui.toast('设置成功')
					} else {
						if(data.resultMsg) {

						} else {
							console.log(data)
						}
					}
				})
			})
		</script>
	</body>

</html>